package com.qinggeng.project.tool.sms.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.tool.sms.domain.SysSms;
import com.qinggeng.project.tool.sms.service.ISysSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 短信通讯Controller
 *
 * @author qinggeng
 * @date 2020-03-14
 */
@RestController
@RequestMapping("/tool/sms")
public class SysSmsController extends BaseController
{
    @Autowired
    private ISysSmsService sysSmsService;

    /**
     * 查询短信通讯列表
     */
    @PreAuthorize("@ss.hasPermi('tool:sms:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSms sysSms)
    {
        startPage();
        List<SysSms> list = sysSmsService.selectSysSmsList(sysSms);
        return getDataTable(list);
    }

    /**
     * 导出短信通讯列表
     */
    @PreAuthorize("@ss.hasPermi('tool:sms:export')")
    @Log(title = "短信通讯", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysSms sysSms)
    {
        List<SysSms> list = sysSmsService.selectSysSmsList(sysSms);
        ExcelUtil<SysSms> util = new ExcelUtil<SysSms>(SysSms.class);
        return util.exportExcel(list, "sms");
    }

    /**
     * 获取短信通讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('tool:sms:query')")
    @GetMapping(value = "/{smsId}")
    public AjaxResult getInfo(@PathVariable("smsId") Long smsId)
    {
        return AjaxResult.success(sysSmsService.selectSysSmsById(smsId));
    }

    /**
     * 新增短信通讯
     */
    @PreAuthorize("@ss.hasPermi('tool:sms:add')")
    @Log(title = "短信通讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSms sysSms)
    {
        return toAjax(sysSmsService.insertSysSms(sysSms));
    }

    /**
     * 修改短信通讯
     */
    @PreAuthorize("@ss.hasPermi('tool:sms:edit')")
    @Log(title = "短信通讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSms sysSms)
    {
        return toAjax(sysSmsService.updateSysSms(sysSms));
    }

    /**
     * 删除短信通讯
     */
    @PreAuthorize("@ss.hasPermi('tool:sms:remove')")
    @Log(title = "短信通讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{smsIds}")
    public AjaxResult remove(@PathVariable Long[] smsIds)
    {
        return toAjax(sysSmsService.deleteSysSmsByIds(smsIds));
    }
}
